<div class="container-fluid">
  <div class="error-container">
    <div class="error-container__content">
      <% unless @error.nil? %>
        <div class="alert alert-danger alert-dismissible" role="alert">
          <%= @error %>
          <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        </div>
      <% end %>
    </div>
  </div>
  <div class="row">
    <div class="col-lg-6">
      <div class="form-group">
        <a href="/queries/new" class="btn btn-default">
          <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add new
        </a>
        <% if (@queries.length > 0) %>
          <button class="btn btn-danger pull-right" id="delete-queries">
            <span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete all
          </button>
        <% end %>
      </div>
      <% if (@queries.length > 0) %>
        <div class="panel panel-default">
          <table class="table table-striped table-queries">
            <colgroup>
              <col style="white-space: nowrap; width: 1%;">
              <col style="white-space: nowrap; width: 1%;">
              <col>
              <col>
              <col>
              <col style="white-space: nowrap; width: 1%;">
            </colgroup>
            <thead>
              <tr>
                <th></th>
                <th></th>
                <th>Name</th>
                <th>Namespaces</th>
                <th>Query</th>
                <th></th>
              </tr>
            </thead>
            <tbody class="sortable-queries">
              <% @queries.each do |q| %>
              <tr data-query-id="<%= q.id %>">
                <td>
                  <span class="glyphicon glyphicon-menu-hamburger text-muted sortable-handle"></span>
                </td>
                <td>
                  <a href="/query?query_id=<%= q.id %>" type="button" class="btn btn-default btn-xs">
                    <span class="glyphicon glyphicon-play" aria-hidden="true"></span>
                  </a>
                </td>
                <td>
                  <a href="/queries/<%= q.id %>/edit">
                    <%= h q.attributes[:name] %>
                  </a>
                </td>
                <td>
                  <% q.namespaces.each do |ns| %>
                    <span class="badge"> <%= ns %></span>
                  <% end %>
                </td>
                <td>
                  <i><%= h q.attributes[:query] %></i>
                </td>
                <td>
                  <button class="btn btn-danger btn-xs delete-query" data-id="<%= q.id %>">
                    <span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
                  </button>
                </td>
              </tr>
              <% end %>
            </tbody>
          </table>
        </div>
      <% else %>
        <div class="alert alert-info">Query list is empty</div>
      <% end %>
      <% if (@queries.length > 10) %>
        <p class="text-muted">
          <i>Only top-10 queries will be available via "Load query" menu.</i>
        </p>
      <% end %>
    </div>
  </div>
</div>
